package com.j.lemon.learn.rocketmq;

import org.apache.rocketmq.acl.common.AclClientRPCHook;
import org.apache.rocketmq.acl.common.SessionCredentials;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class Sender {
    public static void main(String[] args) throws MQClientException {
//        DefaultMQProducer producer = new DefaultMQProducer("demoProducer1",
//                new AclClientRPCHook(new SessionCredentials("csa_audit","audit@1234!")));
        DefaultMQProducer producer = new DefaultMQProducer("demoProducer1");
        producer.setNamesrvAddr("10.28.149.182:9876;10.28.149.188:9876;10.28.149.197:9876");

        producer.setInstanceName("QuickStartProducer");
        producer.start();

        for (int i = 0; i < 1; i++) {
            try {
                Message msg = new Message("topic2",
                        "t1",
                        ("发送测试消息" + i).getBytes(RemotingHelper.DEFAULT_CHARSET)
                );
                SendResult sendResult = producer.send(msg);

                System.out.println("发送结果："+sendResult.toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        producer.shutdown();

    }
}
